package com.chyong.iptv.utils;

import android.content.Context;
import android.content.SharedPreferences;

public class CacheUtil {

    private volatile static CacheUtil mSingleInstance = null;
    private Context context;
    private SharedPreferences sp;
    private int channelPosition = 0;

    private CacheUtil(Context context) {
        this.context = context;
        sp = context.getSharedPreferences("iptv",Context.MODE_PRIVATE);
        channelPosition = sp.getInt("channel", 0);
    }

    public static CacheUtil getInstance(Context context) {
        if (mSingleInstance == null) {
            synchronized (CacheUtil.class) {
                if (mSingleInstance == null) {
                    mSingleInstance = new CacheUtil(context);
                }
            }
        }
        return mSingleInstance;
    }

    public int getChannelPosition() {
        return channelPosition;
    }

    public void setChannelPosition(int channelPosition) {
        this.channelPosition = channelPosition;
        SharedPreferences.Editor editor = sp.edit();
        editor.putInt("channel", channelPosition);
        editor.apply();
    }
}
